package cn.thoughtworks;

import cn.thoughtworks.error.ErrorMessage;
import cn.thoughtworks.factory.MazeFactory;
import cn.thoughtworks.model.Maze;
import cn.thoughtworks.model.Point;
import cn.thoughtworks.model.Size;
import cn.thoughtworks.service.CheckService;

import java.util.Scanner;

/**
 * 主类
 *
 * @author briarbear
 * @blog https://briarbear.github.io
 * @create 2018-07-27-16:12
 */
public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        CheckService checkService = new CheckService();
        while (scanner.hasNext()){
            String input = scanner.nextLine();
            String command = scanner.nextLine();
            String move = scanner.nextLine();
            //1. 检查道路输入是否合法
            Size size = checkService.checkSize(input);
            if (size == null){
                System.out.println(ErrorMessage.INVALID_NUMBER.msg);
                continue;
            }

            //2. 判断命令输入是否有效
            String res = checkService.check(size,command);
            if (res != null){
                System.out.println(res);
                continue;
            }





            //3. 输出结果
            Maze maze = new MazeFactory().create(size,command);

            //4. 判断移动指令
            String[] strs = move.split(" ");

            if (strs.length == 1){
                String[] strings = move.split(",");
                maze.change(new Point(Integer.valueOf(strings[0])*2+1,Integer.valueOf(strings[1])*2+1));
            }else {
                String[] ps = strs[0].split(",");
                maze.move(new Point(Integer.valueOf(ps[0]),Integer.valueOf(ps[1])),strs[1]);

            }
//            maze.change();

            String mazeText = maze.render();
            System.out.print(mazeText);
        }
    }
}
